#include "widget.h"
#include "ui_widget.h"
#include <QNetworkReply>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    manager=new QNetworkAccessManager(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QUrl url(ui->lineEdit->text());
    QNetworkRequest request(url);

    QNetworkReply* response=manager->get(request);

    connect(response,&QNetworkReply::finished,this,[=](){
        if (response->error() == QNetworkReply::NoError) {
                    // 响应正确获取到了.
                    QString html = response->readAll();
                    ui->textEdit->setText(html);
                } else {
                    // 响应出错了
                    ui->textEdit->setText(response->errorString());
                }
                // 还需要对 response 进行释放.
                response->deleteLater();
    });
}
